import cgi, os

def check_against(ip_list):
    try:
        ip = str(cgi.escape(os.environ["REMOTE_ADDR"]))
        if ip in ip_list:
            print ("Content-type: text/html\n\n" +
                   "<h3>You're behavior has caused us to consider you"+
                   " a threat.<br>We have blacklisted you and" +
                   "will behave accordingly.<br><br>" +
                   "Is it worth it?</h3>")
            quit()
    except:
        pass


import data, _mysql
def from_database(password, database,
                  _host="localhost", _user="root",
                  table="blacklist"):
    db = _mysql.connect(host=_host, user=_user,
                        passwd=password, db=database)
    lst = data.getDataInList(db, "SELECT ip FROM " + table)
    check_against([i[0] for i in lst])
